
with open('建行部门.json', 'r', encoding='UTF-8') as f:
    global dt
    dt = eval(f.read())
    for d in dt.values():
        for l in d:
            try:
                l['orgCode']=l['orgCode'].split('_')[1].upper()
            except:
                try:
                    l['orgCode'] = l['orgCode'].split('-')[1].upper()
                except:
                    orgCode=l['orgCode'].strip()
                    if len(orgCode)==18:
                        l['orgCode']=orgCode
                    else:
                       # l['orgCode'] = None
                        d.remove(l)
                  #      print(l['orgCode'],l['orgName'],len(l['orgCode']),sep='\t',end='\n')
                  #      print(f'''报错部门编码{l['orgCode']},部门名称:{l['orgName']},编码长度{len(l['orgCode'])}''')
    # print(dt)


with open('建行部门过滤.json', 'w', encoding='UTF-8') as f1:
    f1.write(str(dt))



with open('建行部门过滤.json', 'r', encoding='UTF-8') as f2:
   print(f2.read())


